<!DOCTYPE html>
<html lang="zh" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <style type="text/css">
        body, html, #allmap {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <script type="text/javascript"
            src="https://api.map.baidu.com/api?v=2.0&ak=ZSXGYc4z7RLVClUmrlL1w9cH9DRghNuw"></script>
    <script src="js/jquery-2.1.4.js"></script>
    <title>地址解析</title>
</head>
<body>
<input id="adress" style="width: 100%;    border: none;    line-height: 40px;    padding: 0 10px;    outline: none;" placeholder="请输入具体地址，按回车键获取经纬度" type="text"
       onchange="changeAdress()">
<input id="lng" class="form-control "  type="hidden">
<input id="lat" class="form-control " type="hidden">
<div id="allmap"></div>
</body>
</html>
<script src="wxJs/utils/storage.js"></script>
<script src="wxJs/utils/contain.js"></script>
<script type="text/javascript">
    // <!--自动定位获取用户位置-->
    var map = new BMap.Map("allmap");
    /*获取用户当前位置坐标*/
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {//授权成功
            ue.clearStorage()
            var mk = new BMap.Marker(r.point);
            map.addOverlay(mk);
            map.panTo(r.point);
            $("#lat").val(r.point.lat);
            $("#lng").val(r.point.lng);
            //传回用户的经纬度
            map.centerAndZoom(r.point, 16);
            var gc = new BMap.Geocoder();
            gc.getLocation(r.point, function (rs) {
                //获取当前点击 位置的 省市县，街道号 和街道名称。并显示在 文本框中
                //街道号 和街道名称 不一定能获取到，有时候为空。
                var addComp = rs.addressComponents;
                var province = addComp.province;
                var city = addComp.city;
                var district = addComp.district;
                var street = addComp.street;
                var streetNumber = addComp.streetNumber;
                var adress = province+city+district+street+streetNumber
                $("#adress").val(adress)

                window.parent.showBackAdress(adress)
            });
            window.parent.showBackMap(r.point.lat,r.point.lng)
        } else {
            alert('failed' + this.getStatus());
        }
    }, {enableHighAccuracy: true});

    var gc = new BMap.Geocoder();
    //点击地图定位
    map.addEventListener("click", function (e) {
        ue.clearStorage()
        //获取当前点击 位置的经纬度，并显示在文本框中
        $("#lat").val(e.point.lat);
        $("#lng").val(e.point.lng);
        map.clearOverlays();
        var new_point = new BMap.Point(e.point.lng, e.point.lat);
        var new_mk = new BMap.Marker(new_point);
        map.addOverlay(new_mk);
        map.panTo(new_point);
        gc.getLocation(new_point, function (rs) {
            //获取当前点击 位置的 省市县，街道号 和街道名称。并显示在 文本框中
            //街道号 和街道名称 不一定能获取到，有时候为空。
            var addComp = rs.addressComponents;
            var province = addComp.province;
            var city = addComp.city;
            var district = addComp.district;
            var street = addComp.street;
            var streetNumber = addComp.streetNumber;
            $("#adress").val(province+city+district+street+streetNumber)
            window.parent.showBackAdress(province+city+district+street+streetNumber)
        });
        window.parent.showBackMap(e.point.lat,e.point.lng)
    });

    function changeAdress() {
        var adress = $("#adress").val();
        gc.getPoint(adress, function (point) {
            if (point) {
                var lat = point.lat;
                var lng = point.lng;
                $("#lat").val(lat);
                $("#lng").val(lng);
                window.parent.showBackMap(lat,lng,adress)
                window.parent.showBackAdress(adress)
                map.centerAndZoom(point, 16);
                map.addOverlay(new BMap.Marker(point));
            } else {
                alert("您选择地址没有解析到结果!");
            }
        }, "湖北省");
    }

</script>